package com.etrans.web.gps.business.evidence.controller;

import com.etrans.web.gps.base.controller.BaseController;
import com.etrans.web.gps.business.evidence.domain.PictureVO;
import com.etrans.web.gps.business.evidence.service.PictureService;
import com.etrans.web.gps.business.report.domain.HistoryImgVO;
import com.etrans.web.gps.business.report.domain.HistoryPicChart;
import com.etrans.web.gps.business.report.service.HisPicService;
import com.etrans.web.gps.business.system.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 证据管理
 *
 * @author czs
 * 2018/04/19
 */
@Controller
@RequestMapping("/picture/*")
public class PictureController extends BaseController {

    @Autowired
    private HisPicService hisPicService;

    @Autowired
    private PictureService pictureService;

    @Autowired
    private CommonService commonService;

    @RequestMapping("index.html")
    public String picture() {
        return "views/business/evidence/picture";
    }

    /**
     * 车辆图片、视频图表（柱状图）统计
     * @param vehicleID 车牌NO
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param enterprisseId 企业id
     * @param eventCode 报警类型编号
     * @return
     */
    @RequestMapping("queryEvidenceChartData.html")
    @ResponseBody
    public HistoryPicChart queryEvidenceChartData(Integer vehicleID, String startTime, String endTime, String enterprisseId,String eventCode) {
        HistoryPicChart chart = pictureService.queryEvidenceChartData(vehicleID,startTime, endTime,enterprisseId,eventCode);
        return chart;
    }


    /**
     * 车辆图片、视频列表
     * @param vehicleID 车牌NO
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param enterprisseId 企业id
     * @param eventCode 报警类型编号
     * @return
     */
    @RequestMapping("queryPictureOrVedioList.html")
    @ResponseBody
    public List<HistoryImgVO> queryPictureList(String vehicleID, String startTime, String endTime, String enterprisseId,String eventCode) {
        List<HistoryImgVO> pictureList = pictureService.queryPictureListByVehicleId(vehicleID,startTime,endTime,enterprisseId,eventCode);
        return pictureList;
    }

  
    
    /**
     * 加载更多车辆图片、视频
     * @param vehicleId 车牌号码
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param enterprisseId 企业id
     * @param eventCode 报警类型编号
     * @return
     */
    @RequestMapping("queryPicListByVehicleIdForMore.html")
    @ResponseBody
    public List<HistoryImgVO> queryPictureListForMore(String vehicleId, String startTime, String endTime, String pageSize,String enterprisseId,String eventCode) {
      
        List<HistoryImgVO> dataList = this.pictureService.queryPictureListForMore(vehicleId,startTime,endTime,pageSize,enterprisseId,eventCode);
        return dataList;
    }

    /**
     *  加载报警类型
     */
    @RequestMapping(value = "getAlarmTypeForInitMap.html")
    @ResponseBody
    public List<Map<String,Object>> queryAlarmTypeForInitMap() {
        return this.pictureService.queryAlarmTypeForInitMap();
    }




    /**
     * 根据车牌号码和时间去查询图片
     * 异常驾驶报表取证
     */
    @RequestMapping(value = "/queryPictureByVehicleNoAndTime.html",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> queryPictureByVehicleNoAndTime(String vehicleNo,String alarmTime){
    	    SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	    try {
				Date gpsTime = sdf.parse(alarmTime);
				return pictureService.queryPictureByVehicleNoAndTime(vehicleNo,gpsTime);
			} catch (ParseException e) {
				e.printStackTrace();
			}
    	    return null;
    }
}
